package com.pzhu.config;


import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * web项目配置类
 */
@Configuration
public class WebAppConfigurer implements WebMvcConfigurer {

    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowedOrigins("*")
                .allowCredentials(true)
                .allowedMethods("GET", "HEAD", "POST", "PUT", "DELETE","OPTIONS")
                .maxAge(3600);
    }
//    地址映射到本地地址
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/image/userAvatar/**").addResourceLocations("file:D:\\webnew\\目录\\household-img\\userAvatar\\");
        registry.addResourceHandler("/image/swiper/**").addResourceLocations("file:D:\\webnew\\目录\\household-img\\swiperImgs\\");
        registry.addResourceHandler("/image/evaluate/**").addResourceLocations("file:D:\\webnew\\目录\\household-img\\evaluate\\");
        registry.addResourceHandler("/image/qrCode/**").addResourceLocations("file:D:\\webnew\\目录\\household-img\\qr_code\\");
        registry.addResourceHandler("/image/thali/**").addResourceLocations("file:D:\\webnew\\目录\\household-img\\thali\\");
    }

}
